<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/6/1
 * Time: 14:22
 */
namespace app\admin\model;
class ShopModel extends BaseModel
{
    protected $table = 'xst_shop';
    protected $rule = [
        'id' => '',
    ];
    protected $msg = [
        'id' => '',
    ];
    /**
     * 现有店铺
     */
    public function index()
    {
        $res = $this->field('s.*,u.nickname')->alias('s')->join('xst_user u','s.uid = u.id','left')->where('s.status',1)->paginate(10,false,['query'=>request()->param()]);
        return $res;
    }
    /**
     * 获取单条信息
     */
    public function getOneId($id)
    {
        return $this->where('id',$id)->find();
    }
    /**
     * 修改店铺信息
     */
    public function edit()
    {
        $name = request()->post('name');
        $type = request()->post('type');
        $id = request()->post('id');
        $data = [
            'name'=>$name,
            'type'=>$type,
        ];
        $res = $this->where('id',$id)->update($data);
        return $res;
    }
    public function del()
    {
        $id = request()->post('id');
        $res = $this->where('id',$id)->delete();
        return $res;
    }
    public function dell()
    {
        $id = request()->post('id');
        $res = $this->where('id','in',$id)->delete();
        return $res;
    }
    /**
     * 店铺审核
     */
    public function examine()
    {
        return $this->field('s.*,u.nickname')->alias('s')->join('xst_user u','s.uid = u.id','left')->where('s.status',0)->paginate(10,false,['query'=>request()->param()]);
    }
    /**
     * 店铺申请同意
    */
    public function status()
    {
        $id = request()->post('id');
        $res = $this->where('id',$id)->update(['status'=>1]);
        return $res;
    }
    /**
     * 店铺申请驳回
     */
    public function no_status()
    {
        $id = request()->post('id');
        $res = $this->where('id',$id)->update(['status'=>2]);
        return $res;
    }
}